home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / SortAlgorithm.java < prev    next >
Text File  |  1998-09-15  |  3KB  |  108 lines

  1. /*
  2.  * @(#)SortAlgorithm.java    1.4 96/12/06
  3.  *
  4.  * Copyright (c) 2070, 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. /**
  32.  * A generic sort demonstration algorithm
  33.  * SortAlgorithm.java, Thu Oct 27 10:32:35 1994
  34.  *
  35.  * @author James Gosling
  36.  * @version     1.6f, 31 Jan 1995
  37.  */
  38.  
  39. class SortAlgorithm {
  40.     /**
  41.      * The sort item.
  42.      */
  43.     private SortItem parent;
  44.  
  45.     /**
  46.      * When true stop sorting.
  47.      */
  48.     protected boolean stopRequested = false;
  49.  
  50.     /**
  51.      * Set the parent.
  52.      */
  53.     public void setParent(SortItem p) {
  54.     parent = p;
  55.     }
  56.  
  57.     /**
  58.      * Pause for a while.
  59.      */
  60.     protected void pause() throws Exception {
  61.     if (stopRequested) {
  62.         throw new Exception("Sort Algorithm");
  63.     }
  64.     parent.pause(parent.h1, parent.h2);
  65.     }
  66.  
  67.     /**
  68.      * Pause for a while and mark item 1.
  69.      */
  70.     protected void pause(int H1) throws Exception {
  71.     if (stopRequested) {
  72.         throw new Exception("Sort Algorithm");
  73.     }
  74.     parent.pause(H1, parent.h2);
  75.     }
  76.  
  77.     /**
  78.      * Pause for a while and mark item 1 & 2.
  79.      */
  80.     protected void pause(int H1, int H2) throws Exception {
  81.     if (stopRequested) {
  82.         throw new Exception("Sort Algorithm");
  83.     }
  84.     parent.pause(H1, H2);
  85.     }
  86.  
  87.     /**
  88.      * Stop sorting.
  89.      */
  90.     public void stop() {
  91.     stopRequested = true;
  92.     }
  93.  
  94.     /**
  95.      * Initialize
  96.      */
  97.     public void init() {
  98.     stopRequested = false;
  99.     }
  100.  
  101.     /**
  102.      * This method will be called to
  103.      * sort an array of integers.
  104.      */
  105.     void sort(int a[]) throws Exception {
  106.     }
  107. }
  108.